package com.nine.pattern.factory.before;

/**
 * @author nine
 * @version 1.0
 * @description 咖啡店
 * @date 2024-06-27 22:03
 */
public class CoffeeStore {

	/**
	 * 此时，就会有耦合，如果再新增其他咖啡，就需要修改CoffeeStore类，违反了开闭原则
	 *
	 * @param type
	 * @return
	 */
	public Coffee orderCoffee(String type) {
		Coffee coffee = null;
		if ("american".equals(type)) {
			coffee = new AmericanCoffee();
		}
		else if ("latte".equals(type)) {
			coffee = new LatteCoffee();
		}
		else {
			throw new RuntimeException("对不起，您点的咖啡没有");
		}
		coffee.addMilk();
		coffee.addSugar();
		return coffee;
	}

}
